/*
01-复杂度1 最大子列和问题
*/
#include <stdio.h>

int main() {
    int n;
    int thisSum = 0, maxSum = 0;
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        int v;
        scanf("%d", &v);
        thisSum += v;
        if (thisSum > maxSum) {
            maxSum = thisSum;
        } else if (thisSum < 0) {
            thisSum = 0;
        }
    }
    printf("%d\n", maxSum);
    return 0;
}
